package com.project.service.Imp;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.BoxBean;
import com.project.bean.MailBean;
import com.project.mapper.IBoxMapper;
import com.project.service.IBoxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

@Service
public class BoxService implements IBoxService {
    @Autowired
    private IBoxMapper boxMapper;

    @Override
    public PageInfo<BoxBean> findByItem(Integer pageNo, Integer userId, String title, LocalDate startDate, LocalDate endDate) {
        PageHelper.startPage(pageNo,2);
        PageInfo<BoxBean> of = PageInfo.of(boxMapper.findByItem(userId, title, startDate, endDate));
        return of;
    }

    @Override
    public MailBean findById(Integer boxId) {
        MailBean byId = boxMapper.findById(boxId);
        boxMapper.updateBoxStatus(boxId);
        return byId;
    }

    @Override
    public void deleteInBox(Integer id) {
        boxMapper.deleteInBox(id);
    }
}
